home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_008 / src / hack.read.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  12KB  |  490 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* hack.read.c version 1.0.1 - tiny correction in SCR_MAGIC_MAPPING */
  3.  
  4. #include "hack.h"
  5.  
  6. extern struct monst *makemon();
  7. int identify();
  8.  
  9. doread() {
  10.     register struct obj *scroll;
  11.     register boolean confused = (Confusion != 0);
  12.     register boolean known = FALSE;
  13.  
  14.     scroll = getobj("?", "read");
  15.     if(!scroll) return(0);
  16.     if(!scroll->dknown && Blind) {
  17.         pline("Being blind, you cannot read the formula on the scroll.");
  18.         return(0);
  19.     }
  20.     if(Blind)
  21.       pline("As you pronounce the formula on it, the scroll disappears.");
  22.     else
  23.       pline("As you read the scroll, it disappears.");
  24.     if(confused)
  25.       pline("Being confused, you mispronounce the magic words ... ");
  26.  
  27.     switch(scroll->otyp) {
  28.  
  29.     case SCR_ENCHANT_ARMOR:
  30.         {    extern struct obj *some_armor();
  31.         register struct obj *otmp = some_armor();
  32.         if(!otmp) {
  33.             strange_feeling(scroll);
  34.             return(1);
  35.         }
  36.         if(confused) {
  37.             pline("Your %s glows silver for a moment.",
  38.                 objects[otmp->otyp].oc_name);
  39.             otmp->rustfree = 1;
  40.             break;
  41.         }
  42.         if(otmp->spe*2 + objects[otmp->otyp].a_ac > 23 &&
  43.             !rn2(3)) {
  44.     pline("Your %s glows violently green for a while, then evaporates.",
  45.             objects[otmp->otyp].oc_name);
  46.             useup(otmp);
  47.             break;
  48.         }
  49.         pline("Your %s glows green for a moment.",
  50.             objects[otmp->otyp].oc_name);
  51.         otmp->cursed = 0;
  52.         otmp->spe++;
  53.         break;
  54.         }
  55.     case SCR_DESTROY_ARMOR:
  56.         if(confused) {
  57.             register struct obj *otmp = some_armor();
  58.             if(!otmp) {
  59.                 strange_feeling(scroll);
  60.                 return(1);
  61.             }
  62.             pline("Your %s glows purple for a moment.",
  63.                 objects[otmp->otyp].oc_name);
  64.             otmp->rustfree = 0;
  65.             break;
  66.         }
  67.         if(uarm) {
  68.             pline("Your armor turns to dust and falls to the floor!");
  69.             useup(uarm);
  70.         } else if(uarmh) {
  71.             pline("Your helmet turns to dust and is blown away!");
  72.             useup(uarmh);
  73.         } else if(uarmg) {
  74.             pline("Your gloves vanish!");
  75.             useup(uarmg);
  76.             selftouch("You");
  77.         } else {
  78.             strange_feeling(scroll);
  79.             return(1);
  80.         }
  81.         break;
  82.     case SCR_CONFUSE_MONSTER:
  83.         if(confused) {
  84.             pline("Your hands begin to glow purple.");
  85.             Confusion += rnd(100);
  86.         } else {
  87.             pline("Your hands begin to glow blue.");
  88.             u.umconf = 1;
  89.         }
  90.         break;
  91.     case SCR_SCARE_MONSTER:
  92.         {    register int ct = 0;
  93.         register struct monst *mtmp;
  94.  
  95.         for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  96.             if(cansee(mtmp->mx,mtmp->my)) {
  97.                 if(confused)
  98.                     mtmp->mflee = mtmp->mfroz =
  99.                     mtmp->msleep = 0;
  100.                 else
  101.                     mtmp->mflee = 1;
  102.                 ct++;
  103.             }
  104.         if(!ct) {
  105.             if(confused)
  106.             pline("You hear sad wailing in the distance.");
  107.             else
  108.             pline("You hear maniacal laughter in the distance.");
  109.         }
  110.         break;
  111.         }
  112.     case SCR_BLANK_PAPER:
  113.         if(confused)
  114.             pline("You see strange patterns on this scroll.");
  115.         else
  116.             pline("This scroll seems to be blank.");
  117.         break;
  118.     case SCR_REMOVE_CURSE:
  119.         {    register struct obj *obj;
  120.         if(confused)
  121.           pline("You feel like you need some help.");
  122.         else
  123.           pline("You feel like someone is helping you.");
  124.         for(obj = invent; obj ; obj = obj->nobj)
  125.             if(obj->owornmask)
  126.                 obj->cursed = confused;
  127.         if(Punished && !confused) {
  128.             Punished = 0;
  129.             freeobj(uchain);
  130.             unpobj(uchain);
  131.             free((char *) uchain);
  132.             uball->spe = 0;
  133.             uball->owornmask &= ~W_BALL;
  134.             uchain = uball = (struct obj *) 0;
  135.         }
  136.         break;
  137.         }
  138.     case SCR_CREATE_MONSTER:
  139.         {    register int cnt = 1;
  140.  
  141.         if(!rn2(73)) cnt += rn2(4) + 1;
  142.         if(confused) cnt += 12;
  143.         while(cnt--)
  144.             (void) makemon(confused ? PM_ACIDBLOB :
  145.             (struct permonst *) 0, u.ux, u.uy);
  146.         break;
  147.         }
  148.     case SCR_ENCHANT_WEAPON:
  149.         if(!uwep) {
  150.             strange_feeling(scroll);
  151.             return(1);
  152.         }
  153.         if(confused) {
  154.             pline("Your %s glows silver for a moment.",
  155.                 objects[uwep->otyp].oc_name);
  156.             uwep->rustfree = 1;
  157.         } else
  158.             if(!chwepon(scroll, 1)) return(1);
  159.         break;
  160.     case SCR_DAMAGE_WEAPON:
  161.         if(confused) {
  162.             pline("Your %s glows purple for a moment.",
  163.                 objects[uwep->otyp].oc_name);
  164.             uwep->rustfree = 0;
  165.         } else
  166.             if(!chwepon(scroll, -1)) return(1);
  167.         break;
  168.     case SCR_TAMING:
  169.         {    register int i,j;
  170.         register int bd = confused ? 5 : 1;
  171.         register struct monst *mtmp;
  172.  
  173.         for(i = -bd; i <= bd; i++) for(j = -bd; j <= bd; j++)
  174.         if(mtmp = m_at(u.ux+i, u.uy+j))
  175.             (void) tamedog(mtmp, (struct obj *) 0);
  176.         break;
  177.         }
  178.     case SCR_GENOCIDE:
  179.         {    extern char genocided[], fut_geno[];
  180.         char buf[BUFSZ];
  181.         register struct monst *mtmp, *mtmp2;
  182.  
  183.         pline("You have found a scroll of genocide!");
  184.         known = TRUE;
  185.         if(confused)
  186.             *buf = u.usym;
  187.         else do {
  188.         pline("What monster do you want to genocide (Type the letter)? ");
  189.             getlin(buf);
  190.         } while(strlen(buf) != 1 || !letter(*buf));
  191.         if(!index(fut_geno, *buf))
  192.             charcat(fut_geno, *buf);
  193.         if(!index(genocided, *buf))
  194.             charcat(genocided, *buf);
  195.         else {
  196.             pline("Such monsters do not exist in this world.");
  197.             break;
  198.         }
  199.         for(mtmp = fmon; mtmp; mtmp = mtmp2){
  200.             mtmp2 = mtmp->nmon;
  201.             if(mtmp->data->mlet == *buf)
  202.                 mondead(mtmp);
  203.         }
  204.         pline("Wiped out all %c's.", *buf);
  205.         if(*buf == u.usym) {
  206.             killer = "scroll of genocide";
  207.             u.uhp = -1;
  208.         }
  209.         break;
  210.         }
  211.     case SCR_LIGHT:
  212.         if(!Blind) known = TRUE;
  213.         litroom(!confused);
  214.         break;
  215.     case SCR_TELEPORTATION:
  216.         if(confused)
  217.             level_tele();
  218.         else {
  219. #ifdef QUEST
  220.             register int oux = u.ux, ouy = u.uy;
  221.             tele();
  222.             if(dist(oux, ouy) > 100) known = TRUE;
  223. #else QUEST
  224.             register int uroom = inroom(u.ux, u.uy);
  225.             tele();
  226.             if(uroom != inroom(u.ux, u.uy)) known = TRUE;
  227. #endif QUEST
  228.         }
  229.         break;
  230.     case SCR_GOLD_DETECTION:
  231.         {    register struct gen *head = confused ? ftrap : fgold;
  232.         register struct gen *gtmp;
  233.  
  234.         if(!head) {
  235.             strange_feeling(scroll);
  236.             return(1);
  237.         } else {
  238.             known = TRUE;
  239.             for(gtmp = head; gtmp; gtmp = gtmp->ngen)
  240.                 if(gtmp->gx != u.ux || gtmp->gy != u.uy)
  241.                     goto outgoldmap;
  242.             /* only under me - no separate display required */
  243.             if(confused)
  244.                 pline("You feel very giddy!");
  245.             else
  246.                 pline("You notice some gold between your feet.");
  247.             break;
  248.         outgoldmap:
  249.             cls();
  250.             for(gtmp = head; gtmp; gtmp = gtmp->ngen)
  251.                 at(gtmp->gx, gtmp->gy, '$');
  252.             prme();
  253.             if(confused)
  254.                 pline("You feel very greedy!");
  255.             else
  256.                 pline("You feel very greedy, and sense gold!");
  257.             more();
  258.             docrt();
  259.         }
  260.         break;
  261.         }
  262.     case SCR_FOOD_DETECTION:
  263.         {    register int ct = 0, ctu = 0;
  264.         register struct obj *obj;
  265.         register char foodsym = confused ? POTION_SYM : FOOD_SYM;
  266.  
  267.         for(obj = fobj; obj; obj = obj->nobj)
  268.             if(obj->olet == FOOD_SYM) {
  269.                 if(obj->ox == u.ux && obj->oy == u.uy) ctu++;
  270.                 else ct++;
  271.             }
  272.         if(!ct && !ctu) {
  273.             strange_feeling(scroll);
  274.             return(1);
  275.         } else if(!ct) {
  276.             known = TRUE;
  277.             pline("You smell %s close nearby.",
  278.                 confused ? "something" : "food");
  279.             
  280.         } else {
  281.             known = TRUE;
  282.             cls();
  283.             for(obj = fobj; obj; obj = obj->nobj)
  284.                 if(obj->olet == foodsym)
  285.                 at(obj->ox, obj->oy, FOOD_SYM);
  286.             prme();
  287.             pline("Your nose tingles and you smell %s!",
  288.                 confused ? "something" : "food");
  289.             more();
  290.             docrt();
  291.         }
  292.         break;
  293.         }
  294.     case SCR_IDENTIFY:
  295.         /* known = TRUE; */
  296.         if(confused)
  297.             pline("You identify this as an identify scroll.");
  298.         else
  299.             pline("This is an identify scroll.");
  300.         useup(scroll);
  301.         objects[SCR_IDENTIFY].oc_name_known = 1;
  302.         if(!confused)
  303.             while(
  304.             !ggetobj("identify", identify, rn2(5) ? 1 : rn2(5))
  305.             && invent
  306.             );
  307.         return(1);
  308.     case SCR_MAGIC_MAPPING:
  309.         {    register struct rm *lev;
  310.         register int num, zx, zy;
  311.  
  312.         known = TRUE;
  313.         pline("On this scroll %s a map!",
  314.             confused ? "was" : "is");
  315.         for(zy = 0; zy < ROWNO; zy++)
  316.             for(zx = 0; zx < COLNO; zx++) {
  317.                 if(confused && rn2(7)) continue;
  318.                 lev = &(levl[zx][zy]);
  319.                 if((num = lev->typ) == 0)
  320.                     continue;
  321.                 if(num == SCORR) {
  322.                     lev->typ = CORR;
  323.                     lev->scrsym = CORR_SYM;
  324.                 } else
  325.                 if(num == SDOOR) {
  326.                     lev->typ = DOOR;
  327.                     lev->scrsym = '+';
  328.                     /* do sth in doors ? */
  329.                 } else if(lev->seen) continue;
  330. #ifndef QUEST
  331.                 if(num != ROOM)
  332. #endif QUEST
  333.                 {
  334.                   lev->seen = lev->new = 1;
  335.                   if(lev->scrsym == ' ')
  336.                     newsym(zx,zy);
  337.                   else
  338.                     on_scr(zx,zy);
  339.                 }
  340.             }
  341.         break;
  342.         }
  343.     case SCR_AMNESIA:
  344.         {    register int zx, zy;
  345.  
  346.         known = TRUE;
  347.         for(zx = 0; zx < COLNO; zx++) for(zy = 0; zy < ROWNO; zy++)
  348.             if(!confused || rn2(7))
  349.             if(!cansee(zx,zy))
  350.                 levl[zx][zy].seen = 0;
  351.         docrt();
  352.         pline("Thinking of Maud you forget everything else.");
  353.         break;
  354.         }
  355.     case SCR_FIRE:
  356.         {    register int num;
  357.  
  358.         known = TRUE;
  359.         if(confused) {
  360.             pline("The scroll catches fire and you burn your hands.");
  361.             losehp(1, "scroll of fire");
  362.         } else {
  363.             pline("The scroll erupts in a tower of flame!");
  364.             if(Fire_resistance)
  365.             pline("You are uninjured.");
  366.             else {
  367.             num = rnd(6);
  368.             u.uhpmax -= num;
  369.             losehp(num, "scroll of fire");
  370.             }
  371.         }
  372.         break;
  373.         }
  374.     case SCR_PUNISHMENT:
  375.         known = TRUE;
  376.         if(confused) {
  377.             pline("You feel guilty.");
  378.             break;
  379.         }
  380.         pline("You are being punished for your misbehaviour!");
  381.         if(Punished){
  382.             pline("Your iron ball gets heavier.");
  383.             uball->owt += 15;
  384.             break;
  385.         }
  386.         Punished = INTRINSIC;
  387.         mkobj_at(CHAIN_SYM, u.ux, u.uy);
  388.         setworn(fobj, W_CHAIN);
  389.         mkobj_at(BALL_SYM, u.ux, u.uy);
  390.         setworn(fobj, W_BALL);
  391.         uball->spe = 1;        /* special ball (see save) */
  392.         break;
  393.     default:
  394.         pline("What weird language is this written in? (%d)",
  395.             scroll->otyp);
  396.         impossible();
  397.     }
  398.     if(!objects[scroll->otyp].oc_name_known) {
  399.         if(known && !confused) {
  400.             objects[scroll->otyp].oc_name_known = 1;
  401.             u.urexp += 10;
  402.         } else if(!objects[scroll->otyp].oc_uname)
  403.             docall(scroll);
  404.     }
  405.     useup(scroll);
  406.     return(1);
  407. }
  408.  
  409. identify(otmp)
  410. register struct obj *otmp;
  411. {
  412.     objects[otmp->otyp].oc_name_known = 1;
  413.     otmp->known = otmp->dknown = 1;
  414.     prinv(otmp);
  415.     return(1);
  416. }
  417.  
  418. litroom(on)
  419. register boolean on;
  420. {
  421.     register int num,zx,zy;
  422.  
  423.     /* first produce the text (provided he is not blind) */
  424.     if(Blind) goto do_it;
  425.     if(!on) {
  426.         if(u.uswallow || !xdnstair || levl[u.ux][u.uy].typ == CORR ||
  427.             !levl[u.ux][u.uy].lit) {
  428.             pline("It seems even darker in here than before.");
  429.             return;
  430.         } else
  431.             pline("It suddenly becomes dark in here.");
  432.     } else {
  433.         if(u.uswallow){
  434.             pline("%s's stomach is lit.", Monnam(u.ustuck));
  435.             return;
  436.         }
  437.         if(!xdnstair){
  438.             pline("Nothing Happens");
  439.             return;
  440.         }
  441. #ifdef QUEST
  442.         pline("The cave lights up around you, then fades.");
  443.         return;
  444. #else QUEST
  445.         if(levl[u.ux][u.uy].typ == CORR) {
  446.             pline("The corridor lights up around you, then fades.");
  447.             return;
  448.         } else if(levl[u.ux][u.uy].lit) {
  449.             pline("The light here seems better now.");
  450.             return;
  451.         } else
  452.             pline("The room is lit.");
  453. #endif QUEST
  454.     }
  455.  
  456. do_it:
  457. #ifdef QUEST
  458.     return;
  459. #else QUEST
  460.     if(levl[u.ux][u.uy].lit == on)
  461.         return;
  462.     if(levl[u.ux][u.uy].typ == DOOR) {
  463.         if(levl[u.ux][u.uy+1].typ >= ROOM) zy = u.uy+1;
  464.         else if(levl[u.ux][u.uy-1].typ >= ROOM) zy = u.uy-1;
  465.         else zy = u.uy;
  466.         if(levl[u.ux+1][u.uy].typ >= ROOM) zx = u.ux+1;
  467.         else if(levl[u.ux-1][u.uy].typ >= ROOM) zx = u.ux-1;
  468.         else zx = u.ux;
  469.     } else {
  470.         zx = u.ux;
  471.         zy = u.uy;
  472.     }
  473.     for(seelx = u.ux; (num = levl[seelx-1][zy].typ) != CORR && num != 0;
  474.         seelx--);
  475.     for(seehx = u.ux; (num = levl[seehx+1][zy].typ) != CORR && num != 0;
  476.         seehx++);
  477.     for(seely = u.uy; (num = levl[zx][seely-1].typ) != CORR && num != 0;
  478.         seely--);
  479.     for(seehy = u.uy; (num = levl[zx][seehy+1].typ) != CORR && num != 0;
  480.         seehy++);
  481.     for(zy = seely; zy <= seehy; zy++)
  482.         for(zx = seelx; zx <= seehx; zx++) {
  483.             levl[zx][zy].lit = on;
  484.             if(!Blind && dist(zx,zy) > 2)
  485.                 if(on) prl(zx,zy); else nosee(zx,zy);
  486.         }
  487.     if(!on) seehx = 0;
  488. #endif    QUEST
  489. }
  490.